package com.ruoyi.project.WebMoudle.WxShopWords.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.WebMoudle.WxShopWords.mapper.WxShopWordsMapper;
import com.ruoyi.project.WebMoudle.WxShopWords.domain.WxShopWords;
import com.ruoyi.project.WebMoudle.WxShopWords.service.IWxShopWordsService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 关键字Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-06-22
 */
@Service
public class WxShopWordsServiceImpl implements IWxShopWordsService 
{
    @Autowired
    private WxShopWordsMapper wxShopWordsMapper;

    /**
     * 查询关键字
     * 
     * @param id 关键字ID
     * @return 关键字
     */
    @Override
    public WxShopWords selectWxShopWordsById(Long id)
    {
        return wxShopWordsMapper.selectWxShopWordsById(id);
    }

    /**
     * 查询关键字列表
     * 
     * @param wxShopWords 关键字
     * @return 关键字
     */
    @Override
    public List<WxShopWords> selectWxShopWordsList(WxShopWords wxShopWords)
    {
        return wxShopWordsMapper.selectWxShopWordsList(wxShopWords);
    }

    /**
     * 新增关键字
     * 
     * @param wxShopWords 关键字
     * @return 结果
     */
    @Override
    public int insertWxShopWords(WxShopWords wxShopWords)
    {
        wxShopWords.setCreateTime(DateUtils.getNowDate());
        return wxShopWordsMapper.insertWxShopWords(wxShopWords);
    }

    /**
     * 修改关键字
     * 
     * @param wxShopWords 关键字
     * @return 结果
     */
    @Override
    public int updateWxShopWords(WxShopWords wxShopWords)
    {
        wxShopWords.setUpdateTime(DateUtils.getNowDate());
        return wxShopWordsMapper.updateWxShopWords(wxShopWords);
    }

    /**
     * 删除关键字对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteWxShopWordsByIds(String ids)
    {
        return wxShopWordsMapper.deleteWxShopWordsByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除关键字信息
     * 
     * @param id 关键字ID
     * @return 结果
     */
    @Override
    public int deleteWxShopWordsById(Long id)
    {
        return wxShopWordsMapper.deleteWxShopWordsById(id);
    }

    @Override
    public List<WxShopWords> selectSelfList(String wordsIds) {
        WxShopWords words = new WxShopWords();
        words.setIsValid("0");
        String[] strings = Convert.toStrArray(wordsIds);
        List<WxShopWords> userPosts = wxShopWordsMapper.selectMylist(strings);
        List<WxShopWords> posts = wxShopWordsMapper.selectWxShopWordsList(words);
        for (WxShopWords all : posts)
        {
            for (WxShopWords my : userPosts)
            {
                if (all.getId().longValue() == my.getId().longValue())
                {
                    all.setFlag(true);
                    break;
                }
            }
        }
        return posts;
    }
}
